#include <vector>
#include <SFML/Network.hpp>
#include "ServerPlayer.hpp"

#include "server.hpp"

using namespace std;

void RemoveFromVector(sf::SocketTCP& Socket, vector<class ServerPlayer>& clients)
{
    for(vector<class ServerPlayer>::iterator iter = clients.begin(); iter != clients.end(); ++iter)
    {
        if(iter->Sock == Socket)
        {
            clients.erase(iter);
            return;
        }
    }
}

void broadcast(sf::Packet Packet, vector<class ServerPlayer>& clients)
{
    for(vector<class ServerPlayer>::iterator iter = clients.begin(); iter != clients.end(); ++iter)
    {
        iter->Sock.Send(Packet);
    }
}

ServerPlayer& GetServerPlayerBySocket(sf::SocketTCP& Socket, vector<class ServerPlayer>& clients)
{
    for(vector<class ServerPlayer>::iterator iter = clients.begin(); iter != clients.end(); ++iter)
    {
        if(iter->Sock == Socket)
        {
            return *iter;
        }
    }
    throw "No such client";
}